<?php
	require "db_factory.php";
	
	class DbDaoBase{
	
		#private static $db_type = DbFactory::get_instance();
		#private static $db_file_name = "site.db";
/*
		(
a INTEGER PRIMARY KEY,
b INTEGER
);
*/
		public static function create_table($tablename , $sql){
			self::dorp_table($tablename);
			$sql = "CREATE TABLE `$tablename` $sql";
			//print $sql;
			self::get_dbh()->exec($sql);
		}
		
		public static function dorp_table($tablename){
			self::get_dbh()->exec("DROP TABLE IF EXISTS `$tablename`");
		}
		#$dbh->exec("insert into staff (id, first, last) values (23, 'Joe', 'Bloggs')");
		public static function insert($tablename , $values){
			$keys = array();
			$col_values = array();
			foreach($values as $key => $value){
				array_push($keys , $key);
				if(is_string($value))
					array_push($col_values  , "'$value'");
				else
					array_push($col_values  , $value);
			}
			$keylist = implode("," , $keys);
			$valuelist = implode("," , $col_values);
			$sql = "insert into $tablename ($keylist) values ($valuelist)";
			//print $sql;
			self::get_dbh()->exec($sql);
		}
		
		public static function find($tablename , $id){
			
		}
		
		private static function get_dbh(){
			return DbFactory::get_instance();
		}
		
		
	}
?>